#include "Float.h"
//#include "./../defines.h"
#include <iostream>
#include <cassert>


using namespace std;

void test0(){
	Float f;
	Float cero3(0);
	stringstream ss;
	
	float flo = 0.0;
	string s;
	ss << fixed << flo;
	s = ss.str();
	Float nCero("7.9");
	Float nCeroC(nCero);
	Float cero(s);
	Float cero2("0.0");
	Float copia(f);
	assert(f==cero);
	assert(f==cero2);
	assert(f==copia);
	Float uno("1,0");
	copia+=uno;
	assert(f != copia);
	Float uno2 = uno;
	uno2+=uno2;
	assert(uno2 != uno);
	uno2 = uno2 - uno2;
   	assert(uno2 == cero);
}

void test1(){
	string a,b;
	cout << "*** Prueba parser ***" << endl;
	a = "93,25";
	while(a!="quit" && a!="q"){
		Float fa(a);
		cout << "para el numero: " << a << " ,su float es: " << fa<< endl;
		cout << "inserte a en el formato numero,numero: ";
		cin >> a;
	}
}

void test2(){
	string a,b;
	a = "93,25";
	b = "23,5";
	cout << " *** Prueba de operadores de comparacion ***"<< endl;
	while(a!="quit" && a!="q"){
		
		Float fa(a);
		Float fb(b);
		string res;
		res = ((fa==fb)?"true":"false");
		cout << a << " == " << b<< " == " << res << '\t';
		res = ((fa!=fb)?"true":"false");
		cout << a << " != " << b<< " == " << res << endl;
		res = ((fa>=fb)?"true":"false");
		cout << a << " >= " << b<< " == " << res << '\t';
		res = ((fa<fb)?"true":"false");
		cout << a << " < " << b<< " == " << res << endl;
		res = ((fa<=fb)?"true":"false");
		cout << a << " <= " << b<< " == " << res << '\t';
		res = ((fa>fb)?"true":"false");
		cout << a << " > " << b<< " == " << res << endl;
		cout << "inserte a: ";
		cin >> a;
		if(a != "q" && a!= "quit"){
			cout << "inserte b: ";
			cin >> b;
		}
	}
}

void test3(){
	string a,b;
	cout << "*** Prueba de la suma (y resta) ***" << endl;
	a = "1,0";
	b = "2,0";
	while(a!="quit" && a!="q"){
		Float fa(a);
		Float fb(b);
		cout << fa << " + " << fb << " == ";
		fa += fb;
		cout << fa << endl;
		cout << "inserte a: ";
		cin >> a;
		if(a != "q" && a!= "quit"){
			cout << "inserte b: ";
			cin >> b;
		}
	}
}

void test4(){
	string a,b;
	cout << "*** Prueba de la multiplicacion ***" << endl;
	a = "1,0";
	b = "2,0";
	while(a!="quit" && a!="q"){
		Float fa(a);
		Float fb(b);
		cout << fa << " * " << fb << " == ";
		fa *= fb;
		cout << fa << endl;
		cout << "inserte a: ";
		cin >> a;
		if(a != "q" && a!= "quit"){
			cout << "inserte b: ";
			cin >> b;
		}
	}
}

void test5(){
	string a,b;
	cout << "*** Prueba shifteo (>>) ***" << endl;
	a = "2,0";
	int n = 2;
	while(a!="quit" && a!="q"){
		Float fa(a);
		cout << fa << " >> ";
		cout << n << " == ";
		fa >>= n;
		cout << fa << endl;
		cout << "inserte a: " ;
		cin >> a;
		if(a != "q" && a!= "quit"){
			cout << "inserte n: " ;
			cin >> n;
		}
	}
}

void test6(){
	Float f1("9.00019");
	float f = 39.81;

	Float f2(f);
	cout << f << endl;
	cout << f2 << endl;
	
	

}

int main() {
	cout << "Corriendo tests minimos y necesarios..." << endl<<endl;
	test0();
	int opt;
	bool salir = false;
	cout << "BIENVENIDO A LOS TESTS DE FLOAT"<<endl;
	cout << "Elija un test, para salir de los test ingrese \"q\" o \"quit\"" << endl;
	while(!salir){
		opt = 0;
		cout << "Opciones:" << endl;
		cout << "++++++++++++++++++"<<endl;
		cout << "1.- Prueba parser " << endl;
		cout << "2.- Prueba de operadores de comparacion " << endl;
		cout << "3.- Prueba de la suma (y resta) " << endl;
		cout << "4.- Prueba de la multiplicacion " << endl;
		cout << "5.- Prueba shifteo (>>) " << endl;
		cout << "6.- Salir " << endl << endl;
		cout << "ingrese opcion: ";cin >> opt;
		cout << endl<<endl;
		if(opt == 1){
			test1();}
		else if(opt == 2){
			test2();}
		else if(opt == 3){
			test3();}
		else if(opt == 4){
			test4();}
		else if(opt == 5){
			test5();}									
		else if(opt == 6){
			salir = true;}
		else if(opt = 'q'){
			salir = true;}
		else{
			cout << "Opcion Incorrecta"<< endl;}
	}
			
	cout << "*******************************" << endl;
	cout << "MUCHAS GRACIAS POR HABER PARTICIPADO" << endl;
	return 0;
}
